﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraBars.Helpers;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using NCKH.Systems;
using NCKH.ThongKe;
using NCKH.View.DanhMuc;
using NCKH.View.XepLichThi.KhoiTao;
using NCKH.Test;

namespace NCKH
{
    using Library;
    using Library.UI;
    using Library.UI.Form;
    public partial class frmMain : XtraForm
    {
        public frmMain()
        {
            InitializeComponent();
            SkinHelper.InitSkinGallery(rgbiSkins, true);
            try
            {
                Program.ConnectionString = DbHelper.GetConnectionString();

                Context db = new Context();
                db.ExecuteQuery<string>(String.Format(DbHelper.FORMATGETTABLES, Properties.Settings.Default.DB));
            }
            catch (Exception)
            {
                INotify.ShowWarning("Không thể mở kết nối đến máy chủ.", "Kết nối máy chủ thất bại");

                if (IForm.ShowDialogForm(new NCKH.Systems.frmConfig(), FormWindowState.Normal, System.Windows.Forms.FormBorderStyle.None) != System.Windows.Forms.DialogResult.OK)
                {
                    Environment.Exit(0);
                }
            }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            
          //  xtraTabControl1.CloseButtonClick += (sender3, e3)
            xtraTabControl1.CloseButtonClick += (sender3, e3) =>
            {
                DevExpress.XtraTab.XtraTabControl xtraTabControl = sender3 as DevExpress.XtraTab.XtraTabControl;
                DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs arg = e3 as DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs;
                (arg.Page as DevExpress.XtraTab.XtraTabPage).Dispose();
            };
            btnDangNhap.PerformClick();  

        }



        private void btnDangNhap_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var result = IForm.ShowDialogForm(new NCKH.Systems.frmLogin(), FormWindowState.Normal, System.Windows.Forms.FormBorderStyle.None);
            if (result == System.Windows.Forms.DialogResult.OK)
            {
                btnDangNhap.Enabled = false;
                btnDangXuat.Enabled = true;
            }
            else
            {
                try
                {
                    Environment.Exit(0);
                }
                catch (Exception)
                {
                    Application.ExitThread();
                }
            }
        }

        private void barButtonItem3_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Close();
        }

        private void btnDangXuat_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

        }

        private void btnThongKeDangKy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
      //      frmTKLopTinChi a = new frmTKLopTinChi();
         //   a.ShowDialog();
            IForm.CloseAllTabPage(xtraTabControl1);
            IForm.OpenTabPage(xtraTabControl1, new frmTKLopTinChi());
        }



        private void btnQuanLyGiangVien_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            IForm.CloseAllTabPage(xtraTabControl1);
            IForm.OpenTabPage(xtraTabControl1, new frmGiangVien());
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTaoHocKy a = new frmTaoHocKy();
            a.ShowDialog();
        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTaoDanhSachThi a = new frmTaoDanhSachThi();
            a.ShowDialog();
        }

        private void barButtonItem3_ItemClick_1(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            frmTest a = new frmTest();
            a.ShowDialog();
        }

       

   
    }
}